<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html class="win-frame">
<head>
<title>代码表详细信息-编辑列表项</title>
<jsp:include page="/common/head.jsp"></jsp:include>
</head>
<body class="iframe-page">
<div class="page-title-wrapper">
    <div class="page-title">
        <div class="page-title-text">
            <span>代码表管理</span>
            <span class="split"></span>
            <span>编辑代码表详情</span>
        </div>
        <a id="goBack" class="btn-return distance-left" href="javascript:;"><i class="icon icon-arrow-left"></i>返回上级</a>
    </div>
    <div class="page-title-border"></div>
</div>

		<form id="editForm" method="post">
		  <div class="form-wrapper">
		  <div class="form-cont">
	           <p class="form-cont-title"><span class="field-required">*</span>所属类别</p>
	           <input  type="text" readonly="readonly" name="type"  value="${codeDetail.type}" class="summer-input summer-validatebox" />
               <input  type="hidden" id="parentId" name="parentId" value="${codeDetail.parentId}" class="summer-input" />
               <input  type="hidden" id="id" name="id" value="${codeDetail.id}" class="summer-input" />
		   </div>               
	        <div class="form-cont">
	           <p class="form-cont-title"><span class="field-required">*</span>名称</p>
	           <input type="text" id="name" name="name" value="${codeDetail.name }" class="summer-input summer-validatebox" data-validatebox="validType:['required','maxLength[50]']"  />
	        </div>           
	        
	        <div class="form-cont">
	           <p class="form-cont-title"><span class="field-required">*</span>代码</p>
	           <input type="text" id="code" name="code" value="${codeDetail.code }" class="summer-input"/>
	        </div> 
	                  
	        <div class="form-cont">
	           <p class="form-cont-title"><span class="field-required">*</span>排序号</p>
	           <input type="text" id="orderNo" name="orderNo" value="${codeDetail.orderNo }" class="summer-input summer-validatebox" data-validatebox="validType:['required','betweenInteger[1,100000]']"  />
	        </div>           
		  </div>
		</form>
		
		<div class="form-btn-wrapper" id="funcbar">
            <a class="btn btn-normal" id="closeBtn">关闭</a>
		</div>
<script>
var CODE_DETAIL_URL = {
        EDIT: basePath+ '/sys/codeDetail/edit',
        CHECK_EXIST: basePath + "/sys/codeDetail/checkCodeDetailExist",
        INIT_STAT: basePath + '/sys/codeDetail/init',//展示右侧
};
var  permission = CommonUtil.getPermission('code');
$(function () {
	//初始化funcbar
	$('#funcbar').prepend($.funcbar({
        type: 'button',
        data: permission,
        permit: ['codeDetail:edit']
    })); 
	
     //表单提交事件
     $('#funcbar').on('click', 'a[data-permit="codeDetail:edit"]', save);
     //关闭按钮事件
     $('#closeBtn,#goBack').on('click',closeWindows); 
     
     //校验代码code是否可用   
	 validateExist('#code',['code'], CODE_DETAIL_URL.CHECK_EXIST, ['required','maxLength[50]','regexp'], "代码可用");
});
  
//保存代码表详情
function save(){
    $("#editForm").form({
        onSubmitSuccess: function (data) {
            parent.frames['codeDetailFrame'].src = CODE_DETAIL_URL.INIT_STAT +'?parentId=${codeDetail.parentId}'+"&id=${param.sysId}";
       		parent.refreshPage('${codeDetail.parentId}');
        },
        ajax: {
            url: CODE_DETAIL_URL.EDIT
        }
    }).form("submit");
}

//关闭窗口
function closeWindows() {
	parent.frames['codeDetailFrame'].src = CODE_DETAIL_URL.INIT_STAT +'?parentId=${codeDetail.parentId}'+"&id=${param.sysId}";
}
  
//校验代码code是否可用  
function validateExist(id, name, url, validType, message) {
    $(id).validatebox({
        rules: {
            regexp: {
                validator: function (value,param) {
                    var result = false,
                        params = {}, 
                        key = name;
                        params[key] = value;
                        params['type'] = '${codeDetail.type}';
                        //params['parentId'] = '${param.sysId}';
                        params['id'] = '${codeDetail.id}';
                    $.ajax({
                        type: 'post',
                        url: url,
                        data: params,
                        dataType: 'json',
                        async: false,
                        success: function (data) {
                            if (data.result == 'exist') {
                                result = false;
                            } else {
                                result = true;
                            }
                        }
                    });
                    return result;
                },
                message: message,
            }
        },
        validType: validType,
        tipPosition: 'right'
    });
}
</script>
</body>
</html>